package com.pk.platform.business.flow.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.pk.platform.business.core.dao.impl.GenericDaoImpl;
import com.pk.platform.business.flow.dao.IFlowDefineDao;
import com.pk.platform.business.flow.vo.WorkFlowVO;
import com.pk.platform.domain.flow.FlowModule;
import com.pk.platform.util.StringConverter;
import com.pk.platform.util.page.ListPage;
import com.pk.platform.util.page.Pager;

public class FlowDefineDaoImpl extends GenericDaoImpl implements IFlowDefineDao {

	public List<FlowModule> queryFlowModule() {
		String hql = "from FlowModule fm order by fm.sort";
		return this.getHibernateTemplate().find(hql);
	}
	
	public List<Map<String, Object>> queryActorsList()
	{
		StringBuffer sql = new StringBuffer();
		sql.append("select id, roleName actorsName, 'role' actorsType from p_role");
		sql.append(" union all select id, deptName actorsName, 'dept' actorsType from p_department");
		sql.append(" union all select id, username actorsName, 'man' actorsType from p_user");
		return this.getSjt().queryForList(sql.toString());
	}
	
	public ListPage queryWorkFlow(WorkFlowVO wfvo, Pager pager)
	{
		StringBuffer sql = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		sql.append("select * from p_workflow wf where 1 = 1");
		if(StringConverter.isNotNull(wfvo.getModuleId()))
		{
			sql.append(" and wf.fmId = ?");
			param.add(wfvo.getModuleId());
		}
		sql.append(" order by wf.flowName");
		return this.getListPage(sql.toString(), param.toArray(), pager);
	}

}
